Ansible Playbook
Playbook
タスク(実施する処理)を記述するファイル
code:playbook.yml
---
- name: Update web servers
hosts: webservers
remote_user: root
tasks:
- name: 最新のApache HTTP Serverをインストールする
ansible.builtin.yum:
name: httpd
state: latest
- name: apacheの設定ファイルを配置する
ansible.builtin.template:
src: /srv/httpd.j2
dest: /etc/httpd.conf
- name: Update db servers
hosts: databases
remote_user: root
tasks:
- name: PostgreSQLの最新版をインストールする
ansible.builtin.yum:
name: postgresql
state: latest
- name: PostgreSQLをサービスとして稼働させる
ansible.builtin.service:
name: postgresql
state: started
プレイブックの実行
$ ansible-playbook playbook.yml
インベントリーファイルを指定して実行
$ ansible-playbook playbook.yml -i inventory_file
--syntax-checkでシンタックスチェック
$ ansible-playbook playbook.yml -i inventory_file --syntax-check
-Cでdry run
$ ansible-playbook playbook.yml -i inventory_file -C
参考
Playbook の使用 — Ansible Documentation
ansible/ansible-examples: A few starter examples of ansible playbooks, to show features and how they work together. See http://galaxy.ansible.com for example roles from the Ansible community for deploying many popular applications.
AWSのためのAnsible入門 | AWSの導入・クラウド運用を総合支援【CapsuleCloud】
関連
dot-files/bin at master · pogin503/dot-files
Ansible モジュール
#Ansible